import java.io.*;
import java.util.*;


// 进行普通文件的复制
public class Test2 {
    public static void main(String[] args) throws IOException {
        Scanner in=new Scanner(System.in);
        System.out.println("请输入要复制的文件路径：");
        String s=in.next();
        File file=new File(s);
        if(!file.isFile()){
            System.out.println(" 输入有误");
            return ;
        }

        System.out.println("请输入要复制到的文件路径：");
        String st=in.next();
        File file1=new File(st);
        if(!file1.isFile()){
            System.out.println(" 输入有误");
            return ;
        }

        System.out.println("是否要进行覆盖： Y/N");
        String ans=in.next();
        if(ans.equals("Y") || ans.equals("y")){
            try(InputStream inputStream=new FileInputStream(file.getAbsoluteFile())){
                try (OutputStream outputStream = new FileOutputStream(file1.getAbsoluteFile())) {
                    while (true) {
                        byte[] bytes = new byte[3];
                        int a = inputStream.read(bytes);
                        if (a == -1) {
                            System.out.println("覆盖完成");
                            break;
                        }
                        //E:\蠢阿伟\test.txt
                        //E:\蠢阿伟\bbb\ccc\test2.txt
                        for(int i=0;i<a;i++){
                            outputStream.write(bytes[i]);
                        }
                    }
                }
            }
        }
    }
}
